home *** CD-ROM | disk | FTP | other *** search
- /* HP.c
- This is the Heap Purge dcmd.
-
- The following MPW commands will build the dcmd and copy it to the
- "Debugger Prefs" file in the System folder. The dcmd's name in
- MacsBug will be the name of the file built by the Linker.
- You must first copy dcmd.h, put.h, dcmdGlue.a.o, put.c.o, and DRunTime.o from the
- dcmds folder into this folder.
-
- Asm hp.a
- C -r -b hp.c #-sym on,novars,notypes -mbg off # for UltraSlimFast
- Link dcmdGlue.a.o hp.c.o hp.a.o put.c.o DRuntime.o "{Libraries}"Interface.o -o hp
- BuildDcmd hp 1235
- #Echo 'include "hp";' | Rez -a -o "{SystemFolder}TMON Folder:DCMD Holder"
- Echo 'include "hp";' | Rez -a -o "{SystemFolder}Debugger Prefs"
-
- DumpObj hp.c.o > hp.dumpObj
- UltraSlimFast hp.dumpObj >hp.UltraSlimFast
-
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include <Files.h>
- #include <Menus.h>
- #include <Traps.h>
-
- #include "dcmd.h"
- #include "put.h"
-
- extern pascal void NewNewPtr();
- extern pascal void NewNewHandle();
- extern pascal void NewReallocHandle();
- extern pascal void NewSetPtrSize();
- extern pascal void NewSetHandleSize();
- extern pascal void NewMoveHHi();
- extern pascal void SaveOldTrapAddress (long address, short addressKind);
- extern pascal void SaveMyA5();
- extern pascal long GetMyA5();
-
- #define kOldNewPtr 0
- #define kOldNewHandle 1
- #define kOldReallocHandle 2
- #define kOldSetPtrSize 3
- #define kOldSetHandleSize 4
- #define kOldMoveHHi 5
-
- #define sysZoneMask 0x0400
-
- Str255 pDumpString;
- char ch;
- Boolean purgingOn;
-
-
- pascal void PurgeIt(long blockAddress, long blockLength, long addrOfMasterPtr,
- short blockType, Boolean locked, Boolean purgeable,
- Boolean resource)
- {
- #pragma unused (blockAddress, blockLength, addrOfMasterPtr, resource)
-
- if ((blockType == relocatableBlock) && (!locked) && (purgeable)) {
- EmptyHandle((Handle)addrOfMasterPtr);
- }
- }
-
-
- Boolean IsSysZone(unsigned short TrapWord)
- {
- return( (TrapWord & sysZoneMask) != 0);
- }
-
-
- pascal void PurgeAllBlocks(unsigned short TrapWord)
- {
- THz oldZone;
- long oldA5;
-
- oldA5 = SetA5(GetMyA5());
- if (purgingOn) {
- if (IsSysZone(TrapWord)) {
- dcmdSwapWorlds();
- oldZone = GetZone();
- SetZone(SystemZone());
- dcmdSwapWorlds();
- }
-
- dcmdForAllHeapBlocks(PurgeIt);
-
- if (IsSysZone(TrapWord)) {
- dcmdSwapWorlds();
- SetZone(oldZone);
- dcmdSwapWorlds();
- }
- }
- (void) SetA5(oldA5);
- }
-
- TrapType GetTrapType(short theTrap)
- {
- // OS traps start with A0, Tool with A8 or AA.
- return((theTrap & 0x0800) ? ToolTrap : OSTrap);
- }
-
- void PatchTrap(short trapNumber, short saveOffset, long newAddress)
- {
- // Use NGetTrapAddress since it is always safer on current machines. Take
- // the result it gives me, and save it off in asm land, for future
- // reference. Then, move in the new address of the routine, my asm glue.
-
- SaveOldTrapAddress(NGetTrapAddress(trapNumber, GetTrapType(trapNumber)),
- saveOffset);
- NSetTrapAddress(newAddress, trapNumber, OSTrap);
- }
-
- void InstallPatches()
- {
- // Patch the traps… These are being patched in the world, not in the
- // debugger world. Switch over to the real world, in case the debugger
- // does world swaps. TMon Pro.
-
- dcmdSwapWorlds();
-
- PatchTrap(_NewPtr, kOldNewPtr, (long) NewNewPtr);
- PatchTrap(_NewHandle, kOldNewHandle, (long) NewNewHandle);
- PatchTrap(_ReallocHandle, kOldReallocHandle, (long) NewReallocHandle);
- PatchTrap(_SetPtrSize, kOldSetPtrSize, (long) NewSetPtrSize);
- PatchTrap(_SetHandleSize, kOldSetHandleSize, (long) NewSetHandleSize);
- PatchTrap(_MoveHHi, kOldMoveHHi, (long) NewMoveHHi);
-
- // Switch back to debugger world.
- dcmdSwapWorlds();
- }
-
-
- pascal void CommandEntry(dcmdBlock* paramPtr)
- {
- switch (paramPtr->request)
- {
- case dcmdInit:
- SaveMyA5();
- purgingOn = false;
- InstallPatches();
- break;
-
- case dcmdHelp:
- dcmdDrawLine("\php");
- dcmdDrawLine("\p Toggle Heap Purge on and off. When on, heap purge purges purgable blocks");
- dcmdDrawLine("\p on NewPtr, NewHandle, ReallocHandle, SetPtrSize, SetHandleSize, and MoveHHi");
- dcmdDrawLine("\p calls.");
- break;
-
- case dcmdDoIt:
- dcmdDrawLine("\pHeap purge is ");
- if (purgingOn)
- dcmdDrawString("\poff.");
- else
- dcmdDrawString("\pon.");
- purgingOn = !purgingOn;
- break;
-
- default:
- PutPStr("\pUnknown request ");
- PutUDec(paramPtr->request);
- PutLine();
- break;
- }
- } // CommandEntry
-